package com.xtck.ha.fault.modules.controller;


import com.xtck.ha.fault.framework.page.PageResult;
import com.xtck.ha.fault.framework.utils.JsonResult;
import com.xtck.ha.fault.modules.convert.ModInfoConvert;
import com.xtck.ha.fault.modules.pojo.dto.ModInfoDTO;
import com.xtck.ha.fault.modules.pojo.entity.ModInfo;
import com.xtck.ha.fault.modules.pojo.vo.ModInfoVO;
import com.xtck.ha.fault.modules.service.ModInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
*  controller
*
* @ClassName: ModInfoController
* @Description: 控制层访问接口
* @author liuyuan
* @date 2025-06-17
*/
@RestController
@RequestMapping("/modinfo1")
@Api(tags={"模型接口管理"})
public class ModInfoController  {
    @Autowired
    private ModInfoService modInfoService;

    public  ModInfoService getService() {
        return modInfoService;
    }
    public ModInfo getEntity() {
        return new ModInfo();
    }
    public ModInfoDTO getDTO() {
        return new ModInfoDTO();
    }

    @PostMapping({"/pageList"})
    @ApiOperation(value = "分页")
    public JsonResult<PageResult<ModInfoVO>> page(@RequestBody ModInfoDTO query){
        PageResult<ModInfoVO> page = getService().page(query);

        return JsonResult.ok(page);
    }

    @GetMapping("/all")
    @ApiOperation(value = "获取所有模型")
    public JsonResult<List<ModInfo>> getAll(){
        List<ModInfo> list = getService().getAllMod();
        if (null != list && list.size() != 0)
            return JsonResult.ok(list);
        else
            return JsonResult.error("未查询到模型信息");
    }

    @GetMapping("{id}")
    @ApiOperation(value = "获取信息")
    public JsonResult<ModInfoVO> get(@PathVariable("id") Long id){
        ModInfo entity = getService().getById(id);

        return JsonResult.ok(ModInfoConvert.INSTANCE.convert(entity));
    }


    @PostMapping("add")
    @ApiOperation(value = "新增")
    public JsonResult<String> save(ModInfoVO vo, MultipartFile modFile){

        return getService().add(vo,modFile);
    }
    @PutMapping
    @ApiOperation(value = "修改")
    public JsonResult<String> update(@RequestBody ModInfoVO vo){
        getService().update(vo);

        return JsonResult.ok();
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    public JsonResult<String> delete(@RequestBody List<Long> idList){
        getService().delete(idList);

        return JsonResult.ok();
    }

    /**
     * 启动模型服务
     * @param modInfo 模型modInfo
     * @return JsonResult
     */
    @PostMapping("startServer")
    @ApiOperation(value = "启动算法服务")
    public JsonResult<String> startAlgorithmServer(@RequestBody ModInfo modInfo) {
        return getService().startAlgorithmServer(modInfo);
    }

    /**
     * 停止模型服务
     * @param modInfo 模型modInfo
     * @return JsonResult
     */
    @PostMapping("stopServer")
    @ApiOperation(value = "停止算法服务")
    public JsonResult<String> stopAlgorithmServer(@RequestBody ModInfo modInfo) {
        return getService().stopAlgorithmServer(modInfo);
    }

}
